package javaDemo02;

import java.util.ArrayList;

public class Shopping_Car {//购物车计算总价类
    private String name;
    private double price;
    private int number;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }


    public static void two(ArrayList<Shopping_Car> car){
        System.out.println("---------------欢迎光临---------------");
        System.out.println("名 称\t\t\t" + "售 价\t\t\t" + "数量\t\t\t" + "金额\t\t\t");
        int sum = 0;
        double p1 = 0;
        for (int i = 0; i < car.size(); i++) {
            System.out.println(car.get(i).getName() +"\t\t\t"+ car.get(i).getPrice() +"\t\t\t"+ car.get(i).getNumber() +"\t\t\t"+ (car.get(i).getPrice() * car.get(i).getNumber()));
            sum += car.get(i).getNumber();
            p1 += (car.get(i).getPrice() * car.get(i).getNumber());
            if(i + 1 == car.size()){
                System.out.println("-------------------------------------");
                System.out.println(car.size() + "项商品：");
                System.out.println("共计:" + sum + "件");
                System.out.println("共:" + p1 + "元");
                System.out.println("-------------------------------------");
            }
        }


    }
}
